package cn.edu.scau.cmi.zengGuanSheng.singleton;

import java.util.ArrayList;
import java.util.List;

public class Marshal1 {

	private static List<Marshal1> marshals = new ArrayList<>();
	private String name;

	private Marshal1(String name) {
		this.name = name;
	}

	public static String getInstances(String name) {
		if (marshals.size() < 10 && !name.equals(null)) {
			marshals.add(new Marshal1(name));
			return new String(name+"已成为十大元帅之一");
		} else
			return new String("十大元帅已经组成！" + name + "不能再当了！");
	}

	public static void print() {
		System.out.println("中国十大元帅分别是:");
		for (int i = 0; i < marshals.size(); i++) {
			System.out.println(marshals.get(i).name);
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public static void clear() {
		marshals.clear();
	}
}